package com.wc.AlgoOJ_train.train1.c4.A303;

import java.util.Scanner;

/**
 * @Author congege
 * @Description 夹角有多大
 * http://43.138.190.70:8888/p/A303
 * @Date Created in 2024/1/3-14:59
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        while (n-- > 0) {
            int h = sc.nextInt();
            int m = sc.nextInt();
            int s = sc.nextInt();

            if (h >= 12) {
                h -= 12;
            }
            // 计算小时与12点的角度
            double hT = (h + m * 1.0 / 60 + s * 1.0 / 3600) * 30;
            // 计算分钟与12点的角度
            double mT = (m + s * 1.0 / 60) * 6;
            double sub = Math.abs(hT - mT);
            if (sub > 180) {
                sub = 360 - sub;
            }
            System.out.println((int) sub);
        }
    }
}
